//
//  AccreditRemindView.m
//  开启授权 - 弹窗提醒
//
//  Created by wxp on 2025/2/27.
//

#import "AccreditRemindView.h"

@implementation AccreditRemindView

#pragma mark - lazy
- (UIView *)viewBack{
    if (_viewBack == nil) {
        _viewBack = [UIView new];
        _viewBack.backgroundColor = COLOR_WHITE;
        _viewBack.width = SCREEN_WIDTH-2*LEFT_MARDIN;
        [GlobalMethod setRoundView:_viewBack color:[UIColor clearColor] numRound:16 width:0];
    }
    return _viewBack;
}
- (UILabel *)labelContent{
    if (_labelContent == nil) {
        _labelContent = [UILabel new];
        _labelContent.textColor = COLOR_CONTENT;
        _labelContent.font = [UIFont boldSystemFontOfSize:12];
        _labelContent.textAlignment = NSTextAlignmentCenter;
        _labelContent.numberOfLines = 0;
        _labelContent.lineSpace = 4;
    }
    return _labelContent;
}
-(UIButton *)btnCancel{
    if (_btnCancel == nil) {
        _btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnCancel.tag = 1;
        [_btnCancel addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btnCancel.backgroundColor = COLOR_PRIMARY;
        [_btnCancel setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        _btnCancel.alpha = 0.5;
        _btnCancel.titleLabel.fontNum = 14;
        _btnCancel.widthHeight = XY((self.viewBack.width-2*30-20)/2, BUTTON_HEIGHT);
        [GlobalMethod setRoundView:_btnCancel color:[UIColor clearColor] numRound:_btnCancel.height/2 width:0];
    }
    return _btnCancel;
}
- (UIButton *)btnEnsure{
    if (_btnEnsure == nil) {
        _btnEnsure = [UIButton buttonWithType:UIButtonTypeCustom];
        _btnEnsure.tag = 2;
        [_btnEnsure addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _btnEnsure.backgroundColor = COLOR_PRIMARY;
        _btnEnsure.titleLabel.fontNum = 14;
        [_btnEnsure setTitleColor:COLOR_BLACK forState:UIControlStateNormal];
        _btnEnsure.widthHeight = XY(self.btnCancel.width, self.btnCancel.height);
        [GlobalMethod setRoundView:_btnEnsure color:[UIColor clearColor] numRound:_btnEnsure.height/2 width:0];
    }
    return _btnEnsure;
}



#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, SCREEN_HEIGHT);
        self.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.4];
        [self cinfigUI];
    }
    return self;
}

//添加subview
- (void)cinfigUI{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.labelContent];
    [self.viewBack addSubview:self.btnCancel];
    [self.viewBack addSubview:self.btnEnsure];
    
    //初始化页面
    [self resetViewWithContent:@"" ensure:@"" cancel:@""];
}

#pragma mark - 手势点击
- (void)tapClick:(UITapGestureRecognizer * )tap{
    [self removeFromSuperview];
}

#pragma mark - 点击事件
- (void)btnClick:(UIButton *)sender{
    [NSObject clickFeedback];
    [sender addClickAnimate];
    switch (sender.tag) {
        case 1:
        {
            [self removeFromSuperview];
        }
            break;
        case 2:
        {
            // 确认
            if(self.blockEnsure){
                self.blockEnsure();
            }
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - 刷新view
- (void)resetViewWithContent:(NSString *)contentStr ensure:(NSString *)ensureStr cancel:(NSString *)cancelStr{
    [self.labelContent fitTitle:isStr(contentStr)?contentStr:@"" variable:self.viewBack.width-2*30];
    self.labelContent.centerXTop = XY(self.viewBack.width/2, (50));
    
    [self.btnCancel setTitle:isStr(cancelStr)?cancelStr:@"cancelar" forState:UIControlStateNormal];
    self.btnCancel.leftTop = XY(30, self.labelContent.bottom+40);
    
    [self.btnEnsure setTitle:isStr(ensureStr)?ensureStr:@"confirmar" forState:UIControlStateNormal];
    self.btnEnsure.leftCenterY = XY(self.btnCancel.right+20, self.btnCancel.centerY);
    
    self.viewBack.height = self.btnEnsure.bottom+self.labelContent.top;
    self.viewBack.centerXCenterY = XY(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
}




@end
